package com.itheima.d2_Collection_List;

import java.util.LinkedList;

/**
 * ArrayList底层基于数组实现
 * LinkedList底层基于双链表实现(======栈式存储========)
 * 对头尾操作更优秀，有一些特定Api:
 *                             getFirst
 *                             removeFirst
 */
public class LinkedListDemo {
    public static void main(String[] args) {
        /**
         * LinkedList可以完成队列和栈的结构
         */

        //1.压栈，入栈
        LinkedList<String> stack = new LinkedList<>();
        stack.addFirst("第1颗子弹");
        stack.addFirst("第2颗子弹");
        stack.addFirst("第3颗子弹");
        stack.addFirst("第4颗子弹");
        System.out.println(stack);
        //出栈
        System.out.println(stack.getFirst());

        //2.队列
        LinkedList<String> queue = new LinkedList<>();
        //入队
        queue.addLast("1号");
        queue.addLast("2号");
        queue.addLast("3号");
        queue.addLast("4号");
        System.out.println(queue);
        //出队
        System.out.println(queue.removeFirst());
        System.out.println(queue.removeFirst());
        System.out.println(queue.removeFirst());
        System.out.println(queue.removeFirst());


    }
}
